home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
DEMON
/
RISCOS2
/
TCP_131S.ARC
/
c
/
misc
< prev
next >
Wrap
Text File
|
1993-03-12
|
3KB
|
134 lines
/* Miscellaneous machine independent utilities */
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "global.h"
#include "misc.h"
/* Case insensitive strcmp */
int stricmp (char *s, char *t)
{
for ( ; tolower(*s) == tolower(*t); ++s, ++t )
if ( *s == '\0' )
return(0);
return (tolower(*s) - tolower(*t));
}
/* C.Strnlcmp: compare two strings for n bytes, treating all letters as
* lower case
*/
int strnlcmp (char *s, char *t, int n)
{
while ( --n >= 0 )
{
if ( *s == '\0' || *t == '\0' || tolower(*s) != tolower(*t) )
return (tolower(*s) - tolower(*t));
++s;
++t;
}
return (0);
}
/* Convert hex-ascii to integer */
int htoi(char *s)
{
int i = 0;
char c;
while((c = *s++) != '\0'){
if(c == 'x')
continue; /* allow 0x notation */
if('0' <= c && c <= '9')
i = (i * 16) + (c - '0');
else if('a' <= c && c <= 'f')
i = (i * 16) + (c - 'a' + 10);
else if('A' <= c && c <= 'F')
i = (i * 16) + (c - 'A' + 10);
else
break;
}
return i;
}
/* replace terminating end of line marker(s) with null */
void rip(register char *s)
{
register char *cp;
if((cp = strchr(s,'\r')) != NULLCHAR)
*cp = '\0';
if((cp = strchr(s,'\n')) != NULLCHAR)
*cp = '\0';
}
/* Case-insensitive string comparison */
int strnicmp(register char *a, register char *b, register int n)
{
char a1, b1;
while (n-- != 0 && (a1 = *a++) != '\0' && (b1 = *b++) != '\0')
{
if (a1 == b1)
continue; /* No need to convert */
a1 = tolower(a1);
b1 = tolower(b1);
if (a1 == b1)
continue; /* Now they match */
if (a1 > b1)
return(1);
if (a1 < b1)
return(-1);
}
return(0);
}
/* Put a long in host order into a char array in network order */
char *put32(register char *cp, int32 x)
{
*cp++ = uchar(x >> 24);
*cp++ = uchar(x >> 16);
*cp++ = uchar(x >> 8);
*cp++ = uchar(x);
return(cp);
}
/* Put a short in host order into a char array in network order */
char *put16(register char *cp, int16 x)
{
*cp++ = uchar(x >> 8);
*cp++ = uchar(x);
return(cp);
}
/* Machine independant, alignment insensitive network-to-host short conversion */
int16 get16(register char *cp)
{
register int16 x;
x = uchar(*cp++);
x <<= 8;
x |= uchar(*cp);
return(x);
}
/* Machine independant, alignment insensitive network-to-host short conversion */
int32 get32(register char *cp)
{
register int32 x;
x = uchar(*cp++);
x <<= 8;
x |= uchar(*cp++);
x <<= 8;
x |= uchar(*cp++);
x <<= 8;
x |= uchar(*cp);
return(x);
}